<?php
defined('IN_YUNYECMS') or exit('No direct script access allowed');
session_save_path(YUNYECMS_SESSION);
session_start();
class base {
	public $lang;
	public $cat;
	public $rootcat;
	public $cfg;
	public $member;
	public $db;
	public $ismobie;
    function __construct() {
		 header("Content-type: text/html; charset=utf-8"); 
		 global $lang;
		 global $cfg;
	     $this->db = core::load_model('common_model');
		 $this->cfg=getcfg();
		 if(!empty($_GET['lang'])&&(is_numeric($_GET['lang'])||ctype_alnum($_GET['lang']))){
	        $this->lang=getcurlang(usafestr(trim($_GET['lang'])));
		}else{
	        $this->lang=getdefaultlang();
		}
		if(is_mobile()) {
			 $this->ismobile=true;	
			}else{
			 $this->ismobile=false;	
		  }
		$this->lang=dolang($this->lang,$this->cfg);
		$this->lang['logo']=dopic($this->lang['logo']);
		$this->lang['icon']=dopic($this->lang['icon']);
		$this->lang['qrcode']=dopic($this->lang['qrcode']);
		$this->lang['copyright']=doimgs($this->lang['copyright']);
		$lang=$this->lang;
		$cfg=$this->cfg;
        define('LAN',empty($this->lang['landir'])?"cn":$this->lang['landir']);
        define('LAN_DEFAULT',$this->lang['isdefault']);
        define('CTD',empty($this->lang['theme'])?"default":$this->lang['theme']);
		if(!empty($cfg['mobilecfg']["displaymode"])){
			if ($this->ismobile) {
		        define('TPL',THEME.CTD."/".LAN."_mobile/");
			 }else{
		        define('TPL',THEME.CTD."/".LAN."/");
			}
		 }else{
		        define('TPL',THEME.CTD."/".LAN."/");
		 }
	    if(!empty($_REQUEST['catid'])){
			  $catid=trim($_REQUEST['catid']);
			  if(!is_numeric($catid)){
				    messagebox("错误的参数","back",'warn');
			  }
		   $catid=usafestr($catid);
		   $catid=getreal_catid($catid,$this->lang['id'],'category',$this->db);
		   $this->cat=getbyid($catid);
		   $this->rootcat=getbyid(getppid($catid));
				if(strlen(RD)>0&&stripos($this->rootcat["pic"],RD)===FALSE){
					$this->rootcat["pic"]=!empty($this->rootcat["pic"])?RD.$this->rootcat["pic"]:''; RD.$this->rootcat["pic"];
				};
	    }
		if($this->cfg['isclose']==1){
			include tpl("closesite");
			exit;
		}
	    $userid=usafestr(yunyecms_strdecode(ugetcookie("userid")));
		if($userid&&is_numeric($userid)){
		    $this->member=getbyid($userid,"member");
			if($this->member["id"]){
			  $this->member['cartnum']=getcount("select count(*) from `#yunyecms_cart` where userid={$this->member["id"]}");
		      $this->member['ordernum']=getcount("select count(*) from `#yunyecms_orders` where userid={$this->member["id"]}");	
			}
		    $this->member['noticenum']=getcount("select count(*) from `#yunyecms_notice` where status=1");
		}
    }
}